package com.sun.showcase.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baidu.ueditor.ActionEnter;

@WebServlet(name = "UEditorServlet", urlPatterns = "/UEditor")  
public class UEditorServlet extends HttpServlet {  

  /**
	 * 
	 */
	private static final long serialVersionUID = 486894080797590590L;

public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{  
      doPost(request, response);  
  }  
    
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
      request.setCharacterEncoding( "utf-8" );    
      response.setHeader("Content-Type" , "text/html");    
      PrintWriter out = response.getWriter();  
//      ServletContext application=this.getServletContext();  
//      String rootPath = application.getRealPath( "/" );    
      String rootPath = "D:\\workspace-neno\\spring-boot\\demo\\demo-web\\src\\main\\resources\\static\\ueditor";    
       
      String action = request.getParameter("action");    
      String result = new ActionEnter( request, rootPath ).exec();    
      if( action!=null &&     
         (action.equals("listfile") || action.equals("listimage") ) ){    
          rootPath = rootPath.replace("\\", "/");    
          result = result.replaceAll(rootPath, "/");    
      }    
      out.write( result );    
  }  

}  